/*
 * @Author: your name
 * @Date: 2021-09-03 15:09:52
 * @LastEditTime: 2021-09-03 16:42:04
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \briup\5-javascript\day10\9-组合继承.js
 */

function Animal(name, age) {
    this.name = name;
    this.age = age;
}
Animal.prototype = {
    constructor: Animal,
    sayName: function() {
        console.log('hello,my name is:' + this.name);
    }
}

function Dog(name, age, type) {
    //经典继承 在子类构造函数借用父类构造函数，要产生关系用call
    //this指代Dog,执行环境对象 
    Animal.call(this, name, age);
    this.type = type;
}
//原型链继承
Dog.prototype = new Animal();
Dog.prototype.constructor = Dog;
Dog.prototype.sayType = function() {
    console.log(this.type);
}
var dog = new Dog("花花", 1, "哈士奇");
console.log(dog); //Dog { name: '花花', age: 1, type: '哈士奇' }
dog.sayName(); //hello,my name is花花
dog.sayType(); //哈士奇